  !
  ! Global Parameter Definitions for meliy
  !
  !
  ! LICENSE AGREEMENT:
  !
  ! You agree that we don't agree to anything.
  !
  !
  ! DISCLAIMER OF WARRANTIES:
  !
  ! This software is provided to you "AS IS," and the authors and
  ! contributors disclaim any warranty or liability obligations to you
  ! of any kind, implied or express, including but not limited to the
  ! warranties of merchantability, fitness for a particular purpose,
  ! and non-infringement.
  ! 
  character*(*),parameter::PROGRAM="meliy"
  character*(*),parameter::VERSION="version 0.0.16_1"
  character*(*),parameter::COPYRIGHT="Copyleft (!c) 2011 Eleseif Laboratory.\n"//&
       "All rights reversed."  
  character*(*),parameter::BUILD_TIME='Sun Nov 20 09:43:40 JST 2011'
  character*(*),parameter::HOST_NAME='regulus.elseifkk.com'
  character*(*),parameter::NOTICE="This is free software; see the soruce for copying conditions.  There is NO\n"//&
       "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
  !
  character*(*),parameter::USAGE=&
       "Usage:\n"//&
       "\tmeliy [options] input_data...\n"//&
       "\n"//&
       "Options:\n"//&
       "\t-A\t\tAutomatically set filename extension.\n"//&
       "\t-B\t\tRun in batch mode.\n"//&
       "\t-C directory\tSet working direcotry.\n"//&
       "\t-D value\tDetector separation in mm.\n"//&
       "\t-L\t\tShow logL (if -v given).\n"//&
       "\t-M value\tUse shared memory for I/O.\n"//&
       "\t-N value\tNumber of iteration.\n"//&
       "\t-O directory\tOutput directory.\n"//&       
       "\t-R value\tFOV radius in mm.\n"//&
       "\t-S value\tNumber of subsets.\n"//&       
       "\t-T \t\tUse delayed subtracted histogram.\n"//&       
       "\t-Z value\tSlice thickness in mm; default 1.\n"//&
       "\t-a value\tMaximum crystal difference.\n"//&
       "\t-b value\tBayesian parameter 0 -> 1; default 0.\n" //&       
       "\t-c\t\tPrint statistical info (if -v given).\n"//&
       "\t-d value\tMinimum detector difference 0 -> 2; default 2.\n"//&
       "\t-f\t\tForce overwrite.\n"//&
       "\t-i file\t\tInput histogram file.\n"//&
       "\t-l file\t\tInput listmode format file.\n"//&
       "\t-m value\tNumber of multiray sampling: 1, 4 or 9.\n"//&
       "\t-w\t\tWrite output for each iteration.\n"//&
       "\t-o file\t\tOutput file.\n"//&
       "\t-p value\tthreshold for Cj: 0 -> 1.\n"//&
       "\t-q quiet mode.\n"//&
       "\t-s value\tNumber of line integral sampling.\n"//&
       "\t-t try decay correction.\n"//&       
       "\t-u try calibration by weight and dose.\n"//&
       "\t-v\t\tBe verbose.\n"//&
       "\t-x value\tNumber of crystal in transaxial.\n"//&
       "\t-y value\tNumber of crystal in axial.\n"//&
       "\t-4\t\t read integer*4 histogram.\n"//&
       "\t--debug\n"//&
       "\t--cf value\t calibration factor\n"//&
       "\t--create-shm\n"//&
       "\t--auto-set-filename-extension\n"//&
       "\t--lmf-swap-at\t\t (if build with DEBUG)\n"//&
       "\t--lmf-flip-axial\t (if build with DEBUG)\n"//&
       "\t--lmf-flip-taxial\t (if build with DEBUG)\n"//&
       "\t--lmf-flip-pmtid\t (if build with DEBUG)\n"//&
       "\t--ofmt string\t\tOutput file format: raw, analyze, dicom.\n"//&
       "\t--oprefix string\tOutput file prefix.\n"//&
       "\t--opostfix string\tOutput file postfix.\n"//&
       "\t--show-cpu\n"//&       
       "\t--use-snn\t\tUse second nearest neighbor.\n"//&
       "\t--write-Cj file\n"//&
       "\t--write-hist-delayed file\n"//&
       "\t--write-hist-prompt file\n"//&
       "\t--write-hist-true file\n"//&
       "\n"
  !
  integer,parameter,public::MAX_STR_LEN      = 512*2
  integer,parameter,public::MAX_LEN_FILENAME = 512*2
  integer,parameter,public::MAXSTRLEN        = MAX_STR_LEN
  integer,parameter,public::MAXPATHLEN       = MAX_LEN_FILENAME
  integer,parameter,public::MAXPROCLEN       = 512

  integer,parameter,public::qp=selected_int_kind(18)

  !
  integer(qp),parameter,public::OPT_NOP                 = 0
  integer(qp),parameter,public::OPT_VERBOSE             = z"0000000000000001"
  integer(qp),parameter,public::OPT_FORCE_OVERWRITE     = z'0000000000000002'
  integer(qp),parameter,public::OPT_DEBUG               = z'0000000000000004'
  integer(qp),parameter,public::OPT_PRINT_STAT          = z'0000000000000008'
  integer(qp),parameter,public::OPT_USE_MRP             = z'0000000000000010'
  integer(qp),parameter,public::OPT_USE_SNN             = z'0000000000000020'
  integer(qp),parameter,public::OPT_USE_SHM             = z'0000000000000040'
  integer(qp),parameter,public::OPT_SHOW_LOGL           = z'0000000000000100'
  integer(qp),parameter,public::OPT_WRITE_EACH          = z'0000000000000200'
  integer(qp),parameter,public::OPT_BATCH               = z'0000000000000400'
  integer(qp),parameter,public::OPT_ASFE                = z'0000000000000800' ! auto set filename extension
  integer(qp),parameter,public::OPT_DECAY_CORRECTION    = z'0000000000001000'
  integer(qp),parameter,public::OPT_CALIBRATION         = z'0000000000002000'
  integer(qp),parameter,public::OPT_USE_TRUE            = z'0000000000004000'
         
  integer(qp),parameter,public::OPT_READ_HIST_INT4      = z'0000000000080000'
  integer(qp),parameter,public::OPT_LMF_SWAP_AT         = z'0100000000000000'
  integer(qp),parameter,public::OPT_LMF_FLIP_AXIAL      = z'0200000000000000'
  integer(qp),parameter,public::OPT_LMF_FLIP_TAXIAL     = z'0400000000000000'
  integer(qp),parameter,public::OPT_LMF_FLIP_PMTID      = z'0800000000000000'

  !
  integer,public,parameter::FT_LIST = -1
  integer,public,parameter::FT_HIST =  1 

  !
  integer,parameter::nshm=3
  integer,parameter::SHMID_TOP  = 0
  integer,parameter,public::SHMID_IN   = 1
  integer,parameter,public::SHMID_OUT  = 2
  integer,parameter,public::SHMID_ENV  = 3
  integer,parameter::SHMENV_DESERTED = -9999

  !
  integer,parameter::nofmt=3
  character*8,parameter::valid_ofmt(nofmt)=[&
       "raw     ",&
       "analyze ",&
       "dicom   "]
  character*4,parameter::ofmt_ext(nofmt)=[&
       ".img",&
       ".img",&
       ".dcm"]
  integer,parameter,public::OFMT_NOP = 0
  integer,parameter,public::OFMT_RAW = 1
  integer,parameter,public::OFMT_ANA = 2
  integer,parameter,public::OFMT_DCM = 3

